﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace Usermanagment.DBConnection
{
   public class UserCreate
    {
        private DBConnect dbc;
		private String message;		

		public UserCreate(DBConnect dbc)
        {
            this.dbc = dbc;
        }


        public Boolean insertUser(String username, String password)
        {
            if (dbc.Connected())
			{        
              	String command = "INSERT INTO PlayersDB(Username,Password,DateReg,CanPlay,CanConnect,Chips) VALUES('" + username + "','" + password + "'," + CurrentTimeMillis() +"," +1+"," +1+","+2000+")";
				MySqlCommand cmd = new MySqlCommand(command, dbc.getCon());                 
                cmd.ExecuteNonQuery();
				cmd.CommandText = "INSERT INTO Playerstat(Username,Wins,Loss,Ratio) VALUES('" + username + "'," + 0 + "," + 0 + ",0)";
				cmd.ExecuteNonQuery();
				message = "Added";
                return true;
            }
            else
            {
                message = "Error Connecting. Please connect to the DB first!";
                return false;

            }
        }

		

		public Int32 CurrentTimeMillis()
		{
		   DateTime staticDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
           TimeSpan timeSpan = DateTime.UtcNow - staticDate;
           return Convert.ToInt32(timeSpan.TotalSeconds);
		}

		public String getStat()
		{
			return message;
		}

    }
}
